<?php

namespace Home\Model;

use Think\Model;

/**
 * Description of GameModel
 *
 * @author xtceetg
 */
class PayModel extends Model {

    protected $tableName = 'pay_log';

    public function create_pay_log($data) {
        return $this->data($data)->add();
    }

    /**
     * 根据订单号获得订单信息
     * @param type $order_num
     */
    public function getByOrderInfo($order_num) {
        return $this->where("order_num='" . $order_num . "' and flag=0")->find();
    }

    /**
     * 根据订单号修改订单状态
     * @param type $order_num
     */
    public function setByOrderInfo($order_num, $third_id, $backtime, $flag = 0, $flag_game = 0) {
        if ($flag == 1 && $flag_game == 0) {
            $data['flag'] = 1;
            $data['plugin_oid'] = $third_id;
            $data['pay_done_time'] = $backtime;
            $data['comfirm_ip'] = get_client_ip();
            return $this->where("order_num='" . $order_num . "' and flag=0")->save($data); // 根据条件更新记录
        } else if ($flag == 1 && $flag_game == 1) {
            $data['flag_game'] = 1;
            return $this->where("order_num='" . $order_num . "' and flag=1")->save($data); // 根据条件更新记录
        }
    }

}
